;=====================================================================
; Equates and Constants
;=====================================================================
;---------------------------------------------------------------------          
; Color constants
;---------------------------------------------------------------------          
black           equ     0000b           ; 00h
blue            equ     0001b           ; 01h
green           equ     0010b           ; 02h
cyan            equ     0011b           ; 03h
red             equ     0100b           ; 04h
magenta         equ     0101b           ; 05h
brown           equ     0110b           ; 06h
lightgray       equ     0111b           ; 07h
darkgray        equ     1000b           ; 08h
lightblue       equ     1001b           ; 09h
lightgreen      equ     1010b           ; 0ah
lightcyan       equ     1011b           ; 0bh
lightred        equ     1100b           ; 0ch
lightmagenta    equ     1101b           ; 0dh
yellow          equ     1110b           ; 0eh
white           equ     1111b           ; 0fh




;==========================================================================
;                                Macros
;==========================================================================

;--------------------------------------------------------------------------
; draws box
;--------------------------------------------------------------------------{{{
MACRO	box   row_start, row_end, col_start, col_end, color
	LOCAL   next_row, next_col, done

	pushad

	mov     dx, row_start           ; initialise dx with start of row

next_row:
	mov     cx, col_start           ; initialise cx with start of col

next_col:
	mov     ah, 0ch                 ; write colored pixel to screen
	mov     al, color
	int     10h

	inc     cx                      ; increment cx by 1
	cmp     cx, col_end             ; check to see if cx has reached col end
	jne     next_col                ; if not equal, go to next col
					
	inc     dx                      ; else, increment dx by 1
	cmp     dx, row_end             ; check to see if dx has reached row end
	jne     next_row                ; if not equal, go to next row

	popad

ENDM	box
;}}}

;--------------------------------------------------------------------------
; draws horizontal lines
;--------------------------------------------------------------------------{{{
MACRO	hline   row, col_start, col_end, color
	LOCAL   next_col

	pushad

	mov     dx, row                 ; initialise dx with row
	mov     cx, col_start           ; initialise cx with start of col
	
next_col:
	mov     ah, 0ch                 ; write colored pixel to screen
	mov     al, color
	int     10h

	inc     cx                      ; increment cx by 1
	cmp     cx, col_end             ; check to see if cx has reached col end
	jne     next_col                ; if not equal, go to next col

	popad

ENDM	hline
;}}}

;--------------------------------------------------------------------------
; draws vertical lines
;--------------------------------------------------------------------------{{{
MACRO	vline   row_start, row_end, col, color
	LOCAL   next_row

	pushad

	mov     cx, col                 ; initialise cx with col
	mov     dx, row_start           ; initialise dx with start of row

next_row:
	mov     ah, 0ch                 ; write colored pixel to screen
	mov     al, color
	int     10h

	inc     dx                      ; increment dx by 1
	cmp     dx, row_end             ; check to see if dx has reached row end
	jne     next_row                ; if not equal, go to next row
						   
	popad

ENDM	vline
;}}}

;--------------------------------------------------------------------------
; changes color
;--------------------------------------------------------------------------{{{
MACRO	change_color    row_start, row_end, col_start, col_end, color_old, color_new
	LOCAL   check_color, next_row, next_col, new_color, continue, complete

	pushad

check_color:
	mov     dx, row_start           ; initialise dx with start of row

next_row:
	mov     cx, col_start           ; initialise cx with start of col

next_col:
	mov     ah, 0dh                 ; retrieves color of pixel from opponent's grid
	mov     bh, 00h
	int     10h

	cmp     al, color_old
	je      new_color
	jmp     continue

new_color:
	mov     ah, 0ch                 ; write colored pixel to screen
	mov     al, color_new
	int     10h

continue:
	inc     cx                      ; increment cx by 1
	cmp     cx, col_end             ; check to see if cx has reached col end
	jne     next_col                ; if not equal, go to next col
				       
	inc     dx                      ; else, increment dx by 1
	cmp     dx, row_end             ; check to see if dx has reached row end
	jne     next_row                ; if not equal, go to next row

complete:
	popad
	
ENDM	change_color
;}}}


;--------------------------------------------------------------------------
; position keyboard cursor to coordinates (row, column)
;--------------------------------------------------------------------------{{{
MACRO	cursor  row, column

	pushad

        mov     ah, 02h                  ; set cursor at position (row, column)
	mov     bh, 00h

	mov     dh, row
	mov     dl, column
	int     10h

	popad

ENDM	cursor
;}}}

;--------------------------------------------------------------------------
; displays message
;--------------------------------------------------------------------------{{{
MACRO	message msg

	pusha

	mov	ax, OFFSET msg
	mov	di, ax
	call	StrWrite

	popa

ENDM
;}}}


;--------------------------------------------------------------------------
; displays center aligned message
; row is the row; col is the middle column of the printed message
;--------------------------------------------------------------------------{{{
MACRO	ctrmsg msg, row, col

	pushad

	mov	ax, OFFSET msg
	mov	di, ax
	call	StrLength
	mov	ax, cx
	div	[two]
	mov	bx, col
	sub	bx, ax
	cursor  row, bl
	call	StrWrite

	popad

ENDM
;}}}


;--------------------------------------------------------------------------
; prints value of eax
;--------------------------------------------------------------------------{{{
MACRO	eaxout	row, col

	pushad

	push	ax
	mov	ax, OFFSET outbuff
	mov	di, ax
	pop	ax
	call	bintoasc

	cursor	row, col
	message	outbuff

	popad

ENDM
;}}}

